package service

import (
	"gitee.com/Yu-eng/Myproject/my-go-blog/config"
	"gitee.com/Yu-eng/Myproject/my-go-blog/dao"
	"gitee.com/Yu-eng/Myproject/my-go-blog/models"
)

func FindPostPigeonhole() (*models.PigeonholeRes, error) {
	//查询所有的文章 进行月份的整理分类额
	categorys, err := dao.GetAllCategory()
	if err != nil {
		return nil, err
	}
	//查询所有的分类
	posts, err := dao.GetPostAll()
	if err != nil {
		return nil, err
	}
	pigeonholeMap := make(map[string][]models.Post)
	for _, post := range posts {
		at := post.CreateAt
		month := at.Format("2006-01")
		pigeonholeMap[month] = append(pigeonholeMap[month], post)
	}

	return &models.PigeonholeRes{
		Viewer:        config.Cfg.Viewer,
		SystemConfig:  config.Cfg.System,
		Categorys:     categorys,
		PigeonholeMap: pigeonholeMap,
	}, nil
}
